namespace Galplay {
  internal class ScriptText : GalScript {
    // 声音的ID
    public int Voice { get; set; }
    public string VoiceFile { get; set; }
    // 文字
    public string Text { get; set; }
    // 角色名
    public string CharaName { get; set; }

    public override bool IsBreakPoint => true;

    public ScriptText(GalScene owner, XmlNode item) : base(owner, item, ScriptType.Text) {
      Voice = item.GetInt("Voice");
      VoiceFile = Kit.AutoAddExtension(item.GetStr("VoiceFile"), ".ogg");
      CharaName = item.GetStr("Name");
      Text = item.InnerText;
    }

    public override void Execute(GameScenePlayer player) {
      player.PlayText(this);
    }

    public string GetText() {
      string text = Text.Replace("\\n", "\n");
      text = UiUtils.AutoWrapText(text, 29);

      if (Kit.NotEmpty(CharaName)) {
        return $"【{CharaName}】：\n{text}";
      } else {
        // 如果使用了CharaTitle，那么增加一行空
        if (GM.Game.UseCharaTitle){
          return "        \n" + text;
        }
        return text;
      }
    }

    public string GetVoiceFile(){
      return Kit.AutoCombine(GM.Game.VoicePath, VoiceFile);
    }

    public static string AutoWrapLine(string text, int max_char) {
      return text;
    }
  }
}